package models

import (
	"gorm.io/gorm/schema"
	"time"
)

type Admin struct {
	Id int64 `json:"id" gorm:"primaryKey"`
	SqlTimeFields
	SqlSaasTenantFields

	Account  string `json:"account" gorm:"type:varchar(64);uniqueIndex;"`
	Password string `json:"password,omitempty" gorm:"type:varchar(32);"`
	Salt     string `json:"salt,omitempty" gorm:"type:varchar(32)"` //密码盐

	Nickname string `json:"nickname" gorm:"type:varchar(64)"`
	Avatar   string `json:"avatar" gorm:"type:varchar(256)"`
	Email    string `json:"email" gorm:"type:varchar(128)"`
	Phone    string `json:"phone" gorm:"type:varchar(32)"` //手机号

	LastLogin *time.Time `json:"last_login,omitempty"`                      //上次登录时间
	LastIp    string     `json:"last_ip,omitempty" gorm:"type:varchar(20)"` //上次登录ip

	IsRoot    int    `json:"is_root" gorm:"type:tinyint"`               //1：是root，0：非root
	ExpiredAt int64  `json:"expired_at"`                                //过期时间，为0不过期，>0为过期时间的秒级时间戳
	Remark    string `json:"remark,omitempty" gorm:"type:varchar(256)"` //备注

	Status int `json:"status,omitempty" gorm:"type:tinyint"` //0:无,1:可用,2：禁用
}

func (ad *Admin) TableName(namer schema.Namer) string {
	return namer.TableName("admin")
}

type AdminLog struct {
	Id int64 `json:"id" gorm:"primaryKey"`
	SqlTimeFields

	AdminId  int64  `json:"admin_id" gorm:"index"`
	Nickname string `json:"nickname" gorm:"type:varchar(64);"`
	Account  string `json:"account" gorm:"type:varchar(64);"`
	Log      string `json:"log" gorm:"type:varchar(256);"`    //日志内容
	Ip       string `json:"ip" gorm:"type:varchar(20);"`      //操作ip
	Device   string `json:"device" gorm:"type:varchar(128);"` //操作设备
	//Extends  string `json:"extends"` //扩展字段

}

func (ad *AdminLog) TableName(namer schema.Namer) string {
	return namer.TableName("admin_log")
}
